package xyz.csmcool.imuser.service.impl;

import lombok.RequiredArgsConstructor;
import xyz.csmcool.imuser.entity.Handle;
import xyz.csmcool.imuser.entity.vo.HandleVo;
import xyz.csmcool.imuser.entity.vo.ReplyVo;
import xyz.csmcool.imuser.mapper.HandleMapper;
import xyz.csmcool.imuser.service.IHandleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import xyz.csmcool.imutil.ExceptionHandler.CommonException;
import xyz.csmcool.imutil.webVo.ResultCode;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author csmcool
 * @since 2022-08-03
 */
@Service
@RequiredArgsConstructor
public class HandleServiceImpl extends ServiceImpl<HandleMapper, Handle> implements IHandleService {

    final HandleMapper handleMapper;

    @Override
    public void addHandle(HandleVo handleVo) {
        Boolean aBoolean = handleMapper.addHandle(handleVo.getUsername(), handleVo.getEmail(), handleVo.getMessage());
        if (!aBoolean) {
            throw new CommonException(ResultCode.CUSTOM_FAIL.setCode(999).setMessage("联系网站负责人失败，稍后重试"));
        }
    }

    @Override
    public void reply(ReplyVo replyVo) {
        Boolean reply = handleMapper.reply(replyVo.getReply(), replyVo.getId());
        if (!reply) {
            throw new CommonException(ResultCode.CUSTOM_FAIL.setCode(999).setMessage("回复失败，稍后重试"));
        }
    }
}
